package ua.kharkov.khpi.tarasenko.bach.web.command.any;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ua.kharkov.khpi.tarasenko.bach.core.Constant;
import ua.kharkov.khpi.tarasenko.bach.core.LocalizedResourceManager;
import ua.kharkov.khpi.tarasenko.bach.core.EShopException;
import ua.kharkov.khpi.tarasenko.bach.web.command.Command;

/**
 * Command to process situation, when specified command was not found.
 * 
 * @author oleksandr
 * 
 */
public class NoSuchCommand extends Command {
	private static final Logger log = Logger.getLogger(NoSuchCommand.class);

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws EShopException {

		String forward = Constant.COMMAND_ERROR_PROCESSING;

		// Create LocalizedResourceManager to get localized error messages
		LocalizedResourceManager LRManager = getLocalizedResourceManager(request);
		String errorMessage = LRManager
				.getMessage("error_message.no_such_command");

		request.setAttribute(Constant.ATTRIBUTE_ERROR_MESSAGE, errorMessage);
		if (log.isTraceEnabled()) {
			log.trace("Set request attribute "
					+ Constant.ATTRIBUTE_ERROR_MESSAGE + "=" + errorMessage);
		}

		if (log.isDebugEnabled()) {
			log.debug("Forward to " + forward);
		}
		return forward;
	}
}
